﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MINERP.DAL;
using MINERP.DAL.PrintManage;
using MINERP.COM;
using MINERP.MODEL.PrintManage;

namespace MINERP.BLL.PrintManage
{
    public  class PaperInfoBLL
    {
        /// <summary>
        /// 校正纸长，纸尾
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="paperLength"></param>
        /// <param name="paperEndLength"></param>
        public void CalibrationPaper(int paperId, double paperLength, double paperEndLength)
        {
            using (newSampleYPDBEntities entities = new newSampleYPDBEntities())
            {
                PaperInfo pi = entities.PaperInfo.FirstOrDefault(p => p.PrintPaperId == paperId);
                pi.Length = paperLength;
                pi.EndPaperLength = paperEndLength;
                pi.PaperEndArea = Convert.ToDouble(pi.EndPaperLength) * Convert.ToDouble(pi.Width) / 10000;
                entities.SaveChanges();
            }
        }

        public void RePrintBord(int paperId)
        {
            using (newSampleYPDBEntities entities = new newSampleYPDBEntities())
            {
                PaperInfo pi = entities.PaperInfo.FirstOrDefault(p => p.PrintPaperId == paperId);
                Board bd = entities.Board.FirstOrDefault(b => b.BoardId == pi.LastBordId);
                if(bd!=null)
                {
                    bd.status = 0;
                }
                pi.PaperConsumptionLength -= bd.length / bd.DPI * 2.54;
               
            }
        }
    }
}
